package xyz.zq.sf.common.mybatis.handler;

import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 租户行处理程序
 *
 * @author hzq
 * @date 2020-12-28 14:42
 */
@Component
@ConditionalOnMissingBean(TenantLineHandler.class)
public class MyBatisTenantLineHandler implements TenantLineHandler {

    /**
     * 忽略的表
     */
    private String[] ignoreTable = {};

    @Override
    public boolean ignoreTable(String tableName) {
        return Arrays.asList(ignoreTable).contains(tableName);
    }

    @Override
    public Expression getTenantId() {
        // 从认证信息里获取机构id
        return new LongValue(1);
    }

    public void setIgnoreTable(String... ignoreTable) {
        this.ignoreTable = ignoreTable;
    }

    public String[] getIgnoreTable() {
        return ignoreTable;
    }
}
